package com.example.ch07userrolemybatis.entity;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Date;
import java.util.List;

/**
 * @description:
 * @author:ScorpioWang
 * @date:2021-11-03-08-12
 */

//实现UserDetails
public class SysUser implements UserDetails {
    private String username;
    private String password;
    private String realname;

    private boolean isExpired;     //账号是否过期
    private boolean isLocked;      //账号是否锁定
    private boolean isCredentials; //凭证是否过期
    private boolean isEnabled;     //是否启用

    private Date createTime;
    private Date loginTime;

    private List<GrantedAuthority> authorities;

    public SysUser(){}

    public SysUser(String username, String password, String realname, boolean isExpired, boolean isLocked, boolean isCredentials, boolean isEnabled, Date createTime, Date loginTime,List<GrantedAuthority> authorities) {
        this.username = username;
        this.password = password;
        this.realname = realname;
        this.isExpired = isExpired;
        this.isLocked = isLocked;
        this.isCredentials = isCredentials;
        this.isEnabled = isEnabled;
        this.createTime = createTime;
        this.loginTime = loginTime;
        this.authorities=authorities;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return username;
    }

    //账号是否过期
    @Override
    public boolean isAccountNonExpired() {
        return isExpired;
    }

    //账号是否锁定
    @Override
    public boolean isAccountNonLocked() {
        return isLocked;
    }

    //凭证是否过期
    @Override
    public boolean isCredentialsNonExpired() {
        return isCredentials;
    }

    //是否启用
    @Override
    public boolean isEnabled() {
        return isEnabled;
    }

    public String getRealname() {
        return realname;
    }
}
